package wt.hpad.model.holder;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.daimajia.swipe.implments.SwipeItemMangerImpl;

import wt.hpad.ConstantFields;
import wt.hpad.R;
import wt.hpad.base.BaseHolder;
import wt.hpad.base.BaseRvSwAdapter;
import wt.hpad.model.bean.DishDetail;

/**
 * Created by wt on 12.25.
 */

public class DishDetailNmHolder extends BaseHolder<DishDetail> {
    private TextView tv_dishName_dd;
    private TextView tv_dishNum_dd;
    private TextView tv_tip_dd;
    private TextView tv_isCompleted_dd;
    private View line;


    public DishDetailNmHolder(Context context, ViewGroup parent, BaseRvSwAdapter<DishDetail> adapter, int layoutID) {
        super(context, parent, adapter, layoutID);
    }

    @Override
    public void setItemView(View itemView) {
        tv_dishName_dd = (TextView) itemView.findViewById(R.id.tv_dishName_ddn);
        tv_dishNum_dd = (TextView) itemView.findViewById(R.id.tv_dishNum_ddn);
        tv_isCompleted_dd = (TextView) itemView.findViewById(R.id.tv_isCompleted_ddn);
        tv_tip_dd = (TextView) itemView.findViewById(R.id.tv_tip_ddn);
        line = itemView.findViewById(R.id.lv);
    }

    @Override
    public void bindItemValue(DishDetail bean) {
        isHideSomeItem(bean);
        if (bean.dishIsCompleted == ConstantFields.ITEM_TYPE_SERVED) {
            greenAllTv();
            tv_isCompleted_dd.setText("(已上)");
        } else if (bean.dishIsCompleted == ConstantFields.ITEM_TYPE_RETREAT) {
            redAllTv();
            tv_isCompleted_dd.setText("(已退)");
        }
        tv_dishName_dd.setText(bean.dishName);
        tv_tip_dd.setText(bean.tipOfCook);
        tv_dishNum_dd.setText(bean.dishNum + "");
    }


    private void greenAllTv() {
        tv_dishName_dd.setTextColor(Color.rgb(45, 140, 90));
        tv_dishNum_dd.setTextColor(Color.rgb(45, 140, 90));
        tv_isCompleted_dd.setTextColor(Color.rgb(45, 140, 90));
        tv_tip_dd.setTextColor(Color.rgb(45, 140, 90));
    }

    private void redAllTv() {
        tv_dishName_dd.setTextColor(Color.rgb(160, 132, 240));
        tv_dishNum_dd.setTextColor(Color.rgb(160, 132, 240));
        tv_isCompleted_dd.setTextColor(Color.rgb(160, 132, 240));
        tv_tip_dd.setTextColor(Color.rgb(160, 132, 240));
    }

    @Override
    public void bindSwItemValue(SwipeItemMangerImpl mItemManger, DishDetail bean, int position) {
    }

    /**
     * 如果没有"口味"则隐藏之
     */
    private void isHideSomeItem(DishDetail bean) {
        if (TextUtils.isEmpty(bean.tipOfCook)) {
            tv_tip_dd.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
        } else {
            tv_tip_dd.setVisibility(View.VISIBLE);
            line.setVisibility(View.VISIBLE);
            tv_tip_dd.setText(bean.tipOfCook);
        }
    }
}
